import unittest

from SmallShop.BaseObject.BaseObject import BaseObject

from selenium.webdriver.common.by import By

from SmallShop.PageObject.PageObject import PageObject

from time import sleep

from ddt import ddt,file_data

from selenium import webdriver

class shopAdd(BaseObject):

    url = "http://www.litemall360.com:8081/#/promotion/ad"

    ClickSdvertising = (By.CSS_SELECTOR,"#app > div > div.sidebar-container.el-scrollbar > div.scrollbar-wrapper.el-scrollbar__wrap > div > ul > div:nth-child(5) > li > ul > div:nth-child(1) > a > li")

    AddSdvertising = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.filter-container > button:nth-child(4) > span")

    AddTitle = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(1) > div > div > input")

    AddData = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(2) > div > div > input")

    AddPicture = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(3) > div > div > div.el-upload.el-upload--text > i")

    AddValue = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(3) > div > div > div.el-upload.el-upload--text > input")

    AddActivity = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(5) > div > div > input")

    ClickYes = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__body > form > div:nth-child(6) > div > div > div > input")

    ClickKeyTwo = (By.CSS_SELECTOR,"body > div:nth-child(13) > div.el-scrollbar > div.el-select-dropdown__wrap.el-scrollbar__wrap > ul > li:nth-child(2)")

    ClickButton = (By.CSS_SELECTOR,"#app > div > div.main-container > section > div > div.el-dialog__wrapper > div > div.el-dialog__footer > div > button.el-button.el-button--primary.el-button--medium > span")


    def SdvertisingAdd(self,title,data1,activity):

        self.BaseUrl(self.url)

        sleep(2)

        self.ClickData(self.ClickSdvertising)

        sleep(2)

        self.ClickData(self.AddSdvertising)

        sleep(2)

        self.SendValue(self.AddTitle,title)

        sleep(2)

        self.SendValue(self.AddData,data1)

        sleep(2)

        self.ClickData(self.AddPicture)

        sleep(2)

        self.SendValue(self.AddValue,"D:\\1.png")

        sleep(2)

        self.SendValue(self.AddActivity,activity)

        sleep(2)

        self.ClickData(self.ClickYes)

        sleep(2)


        self.ClickData(self.ClickButton)


if __name__ == '__main__':

    drive = webdriver.Chrome()

    drive.maximize_window()

    login = PageObject(drive)

    login.test_UserLogin("admin123","admin123")

    ar = shopAdd(drive)

    ar.SdvertisingAdd("上海","上海今天好热","www.baidu.com")

